﻿
<Assembly: System.Windows.Markup.XmlnsDefinition("http://wpfglue.wordpress.com/validation", "WPFGlue.Validation")> 
<Assembly: System.Windows.Markup.XmlnsPrefix("http://wpfglue.wordpress.com/validation", "v")> 
Namespace Validation
    Public Class Validation
        Inherits DependencyObject

        Public Shared ReadOnly AdornedElementToolTipProperty As DependencyProperty = DependencyProperty.RegisterAttached("AdornedElementToolTip", GetType(Object), GetType(Validation), New PropertyMetadata(Nothing, AddressOf OnAdornedElementToolTipChanged))
        Public Shared Function GetAdornedElementToolTip(ByVal d As DependencyObject) As Object
            Return d.GetValue(AdornedElementToolTipProperty)
        End Function
        Public Shared Sub SetAdornedElementToolTip(ByVal d As DependencyObject, ByVal value As Object)
            d.SetValue(AdornedElementToolTipProperty, value)
        End Sub
        Private Shared Sub OnAdornedElementToolTipChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
            Dim placeholder As AdornedElementPlaceholder = TryCast(d, AdornedElementPlaceholder)
            If placeholder IsNot Nothing Then
                Dim control As Control = TryCast(placeholder.AdornedElement, Control)
                If control IsNot Nothing Then
                    control.ToolTip = e.NewValue
                End If
            End If
        End Sub


        Private Shared ReadOnly ErrorTemplateSuppressorProperty As DependencyProperty = DependencyProperty.RegisterAttached("ErrorTemplateSuppressor", GetType(ErrorTemplateSuppressor), GetType(Validation), New PropertyMetadata(AddressOf WPFGlue.Framework.StickyComponentManager.OnStickyComponentChanged))
        Public Shared ReadOnly SuppressErrorTemplateProperty As DependencyProperty = DependencyProperty.RegisterAttached("SuppressErrorTemplate", GetType(Boolean), GetType(Validation), New FrameworkPropertyMetadata(False, FrameworkPropertyMetadataOptions.Inherits, AddressOf OnSuppressErrorTemplateChanged))
        Public Shared Function GetSuppressErrorTemplate(ByVal d As DependencyObject) As Boolean
            Return d.GetValue(SuppressErrorTemplateProperty)
        End Function
        Public Shared Sub SetSuppressErrorTemplate(ByVal d As DependencyObject, ByVal value As Boolean)
            d.SetValue(SuppressErrorTemplateProperty, value)
        End Sub
        Private Shared Sub OnSuppressErrorTemplateChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
            If e.OldValue Then
                d.SetValue(ErrorTemplateSuppressorProperty, Nothing)
            End If
            If e.NewValue Then
                d.SetValue(ErrorTemplateSuppressorProperty, New ErrorTemplateSuppressor)
            End If
        End Sub



        Public Shared ReadOnly TestObjectProperty As DependencyProperty = DependencyProperty.RegisterAttached("TestObject", GetType(Object), GetType(Validation))
        Public Shared Function GetTestObject(ByVal d As DependencyObject) As Object
            Return d.GetValue(TestObjectProperty)
        End Function
        Public Shared Sub SetTestObject(ByVal d As DependencyObject, ByVal value As Object)
            d.SetValue(TestObjectProperty, value)
        End Sub


        Public Shared ReadOnly RuleSetterProperty As DependencyProperty = DependencyProperty.RegisterAttached("RuleSetter", GetType(ValidationRuleSetter), GetType(Validation), New PropertyMetadata(AddressOf WPFGlue.Framework.StickyComponentManager.OnStickyComponentChanged))
        Public Shared Function GetRuleSetter(ByVal d As DependencyObject) As ValidationRuleSetter
            Return d.GetValue(RuleSetterProperty)
        End Function
        Public Shared Sub SetRuleSetter(ByVal d As DependencyObject, ByVal value As ValidationRuleSetter)
            d.SetValue(RuleSetterProperty, value)
        End Sub

    End Class
End Namespace